package edu.drexel.cs575.taskManager.gui.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.google.common.hash.HashFunction;

import edu.drexel.cs575.taskManager.common.ServiceFactory;
import edu.drexel.cs575.taskManager.common.serviceDropSpot.broker.BrokerCaller;
import edu.drexel.cs575.taskManager.common.serviceDropSpot.user.UsermgmtCaller;
import edu.drexel.cs575.taskManager.gui.Helper;
import edu.drexel.cs575.taskManager.gui.controller.tasks.TaskController;
import edu.drexel.cs575.taskManager.gui.model.tasks.TaskList;
import edu.drexel.cs575.taskManager.gui.model.users.LoginCredentials;
import edu.drexel.cs575.taskManager.gui.model.users.User;

@Controller
public class IndexController {
	
	@RequestMapping("/index")
	public ModelAndView getIndex(HttpServletRequest request){
		if(Helper.isLoggedIn(request)){
			try{
				BrokerCaller taskService = ServiceFactory.getTaskService();
				return new ModelAndView("displayAllTasks", "command", TaskController.getTaskList(request, taskService, Helper.getUserName(request)));
			}
			catch(Throwable t){
				TaskList taskList = TaskController.getTaskList(Helper.getUserName(request));
				return new ModelAndView("displayAllTasks", "command", taskList);
			}
		}
		else{
	        return new ModelAndView("index", "command", new LoginCredentials());
		}
	}

}
